//
//  benDiHuanCun.m
//  UI_A
//
//  Created by dllo on 16/3/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "benDiHuanCun.h"

@implementation benDiHuanCun
+(void)saveResponseObject:(NSDictionary *)dic ld:(NSInteger)i{
    
    NSArray *sandBox = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *sandBoxPath = sandBox[0];
    NSString *docPath = [sandBoxPath stringByAppendingPathComponent:[NSString stringWithFormat: @"navigate%ld.plist",i]];;
    [NSKeyedArchiver archiveRootObject:dic toFile:docPath];
    
    
    
    
}
+(NSDictionary *)findResponseObject:(NSInteger)i{
    NSArray *sandBox = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *sandBoxPath = sandBox[0];
    NSString *docPath = [sandBoxPath stringByAppendingPathComponent:[NSString stringWithFormat: @"navigate%ld.plist",i]];;
    NSDictionary *responseObject = [NSKeyedUnarchiver unarchiveObjectWithFile:docPath];
    
    return responseObject;
}
+ (float )getCachesSize{
    NSString * folderPath=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    // NSString * myCaches=[folderPath stringByAppendingPathComponent:@"Caches"];
    //NSLog(@"adsasdassadsadsad   %@",myCaches);
    NSFileManager* manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:folderPath]){
        return 0;
    }
    NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
    NSString* fileName;
    CGFloat folderSize = 0;
    while ((fileName = [childFilesEnumerator nextObject]) != nil){
        NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
        folderSize += [self fileSizeAtPath:fileAbsolutePath];
    }
    return folderSize;
}
+ (float) fileSizeAtPath:(NSString*) filePath{
    NSFileManager* manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:filePath]){
        return [[manager attributesOfItemAtPath:filePath error:nil] fileSize]/(1024.0*1024);
    }
    return 0;
}
@end
